package edu.uc.labs.MobilePrinting.PrintUtils;

import edu.uc.labs.MobilePrinting.Configurator;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import org.xml.sax.SAXException;
import org.apache.log4j.Logger;

/**
 * 
 * @author Matthew Silbernagel
 */
public class PrinterFinder {

	public static ArrayList<Printer> getList(String directory) {
		Logger logger = Configurator.LOGGER;
		ArrayList<Printer> printers = null;
		try {
			PrinterParser parser = new PrinterParser();
			String fileToParse = directory + Configurator.XMLFILE;
			logger.debug("The file to parse for building the printer list is "
					+ fileToParse);
			printers = parser.parse(fileToParse);
		} catch (SAXException ex) {
			logger.debug(ex.toString());
		} catch (IOException ex) {
			logger.debug(ex.toString());
		} catch (XPathExpressionException ex) {
			logger.debug(ex.toString());
		} catch (ParserConfigurationException ex) {
			logger.debug(ex.toString());
		}
		if (!printers.isEmpty()) {
			return printers;
		}
		return printers;

	}

}
